package com.example.demo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @author shenrui
 * @date 2021/9/19
 * @description 统一设置跳转
 */
@Controller
public class PageController {
    //管理员主界面跳转
    @RequestMapping("/admin_main")
    public String adminMain() {
        return "admin/admin_main";
    }

    //用户主界面跳转
    @RequestMapping("/user_main")
    public String userMain() {
        return "user/user_main";
    }
    //用户列表界面跳转
    @RequestMapping("/user_list")
    public String userList() {
        return "user/user_list";
    }
    //管理员登录页跳转
    @GetMapping(value = {"/admin_login"})
    public String adminLoginPage(HttpServletRequest request){
        HttpSession session = request.getSession();
        if (session.getAttribute("adminLogin") != null) {
            return "redirect:admin_main";
        }
        return "admin/admin_login";
    }

    //用户登录页跳转
    @GetMapping(value = {"/","/user_login"})
    public String userLoginPage(HttpServletRequest request){
        HttpSession session = request.getSession();
        //登录过后无需登录
        if (session.getAttribute("userLogin") != null) {
            return "redirect:user_main";
        }
        return "user/user_login";
    }
    //修改信息界面跳转
    @RequestMapping("/revice_user_info")
    public String userInfoJump() {
        return "admin/revice_user_info";
    }
    //用户注册页跳转
    @GetMapping(value = "/user_register")
    public String userRegisterPage(HttpServletRequest request){
        HttpSession session = request.getSession();
        //登录过后无需注册
        if (session.getAttribute("userLogin") != null) {
            return "redirect:user_main";
        }
        return "user/user_register";
    }
    //游戏界面跳转
    @RequestMapping("/user_game")
    public String userGame() {
        return "user/user_game";
    }
    //游戏结果跳转
    @RequestMapping("/game_result")
    public String gameSubmit() {
        return "user/game_result";
    }
    //游戏记录跳转
    @RequestMapping("/game_list")
    public String gameList() {
        return "user/game_list";
    }
}
